package com.titaniume.rqbbitmq.six;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.titaniume.rqbbitmq.util.RabbitMqUtils;

import java.util.Scanner;

/**
 * @program: rqbbitmq-hello
 * @description: 生产者 direct
 * @author: titaniume
 * @create: 2021-12-22 13:39
 */
public class DirectLogs {

    public static final String EXCHANGE_NAME ="direct_logs";

    public static void main(String[] args) throws  Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //声明一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入消息:");
        while (scanner.hasNext()){
            String message = scanner.nextLine();
            channel.basicPublish(EXCHANGE_NAME,"info",null,message.getBytes("UTF-8"));
            System.out.println("生产者发出消息：" + message);
        }
    }
}